#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

void callback(const boost::system::error_code&) {
	std::cout << "Hello world!" << std::endl;
}

void callback2(const boost::system::error_code&) {
	std::cout << "Second call, but first run." << std::endl;
}


int main()
{
	boost::asio::io_service io;
	//连接代码，底层IO系统、网络之间的桥梁，生命周期长可以从一开始定义出来
	//不要做成single模式
	boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
	t.async_wait(callback); 
	//需要绑定io_service，io是个&，
	boost::asio::deadline_timer t2(io, boost::posix_time::seconds(2));
	t2.async_wait(callback2);
	//非阻塞
	std::cout << "Start run.\n";
	io.run();
	//此时调用callback
	std::cout << "Finish run.\n";
	return 0;
}
